package 
{
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.utils.Dictionary;
	/**
	 * ...
	 * @author Ivan
	 */
	public class InputSystem 
	{
		private static var _stage:Stage;
		private static var keyPools:Dictionary = new Dictionary();
		public static var mouseStats:MouseStats;
		private static var _mousePosition:Point = new Point();
		
		public function InputSystem() 
		{
			
		}
		
		public static function register(stage:Stage):void 
		{
			mouseStats = new MouseStats();
			_stage = stage;
			_stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
			_stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
			_stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			_stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
			_stage.addEventListener(MouseEvent.RIGHT_MOUSE_DOWN, onRightMouseDown);
			_stage.addEventListener(MouseEvent.RIGHT_MOUSE_UP, onRightMouseUp);
		}
		
		public static function getMousePosition():Point 
		{
			_mousePosition.x = _stage.mouseX;
			_mousePosition.y = _stage.mouseY;
			return _mousePosition;
		}
		
		static private function onRightMouseUp(e:MouseEvent):void 
		{
			mouseStats.rightDown = false;
			
		}
		
		static private function onRightMouseDown(e:MouseEvent):void 
		{
			mouseStats.rightDown = true;
		}
		
		static private function onMouseUp(e:MouseEvent):void 
		{
			mouseStats.leftDown = false;
		}
		
		static private function onMouseDown(e:MouseEvent):void 
		{
			mouseStats.leftDown = true;
		}
		
		static private function onKeyDown(e:KeyboardEvent):void 
		{
			keyPools[e.keyCode] = true;
		}
		
		static private function onKeyUp(e:KeyboardEvent):void 
		{
			delete keyPools[e.keyCode]
		}
		
		public static function isKeyDown(key:int):Boolean
		{
			return keyPools[key] == true;
		}
		
		
	}
	
	

}
import flash.display.Stage;
import flash.geom.Point;
class MouseStats 
{
		public var leftDown:Boolean = false;
		public var rightDown:Boolean = false;
		public var middleDown:Boolean = false;
		private var _location:Point = new Point();
		public var stage:Stage;
		
		public function get location():Point
		{
			_location.x = stage.mouseX;
			_location.y = stage.mouseY;
			return _location;
		}

		public function MouseStats() 
		{	
		}
	}


